/**
 * Created by HUANGFR2 on 8/19/2016.
 */
const mongoose = require('mongoose');
const Stomp = require('stomp-client');
const config = require('../core/server/config/config');

var client = new Stomp(config.jmsServer.url, config.jmsServer.port, '', '');

module.exports = {
    publishComplaint : function  (oid, mid, cid, cb) {
        var client = new Stomp(config.jmsServer.url, config.jmsServer.port, '', '');
        client.connect(function (seesionId) {
            //console.log('JMS client connected!...');
            var message = {
                oId : oid,
                mId : mid,
                cId : cid
            };
            client.publish(config.jmsQueue.complaint_destination, JSON.stringify(message));
/*            client.disconnect(function () {
                console.log('jms '+config.jmsQueue.complaint_destination+' disconnect');
                if(cb){
                    cb();
                }
            })*/
        });
    },
    publicMerchant : function (mid, cb) {
        var client = new Stomp(config.jmsServer.url, config.jmsServer.port, '', '');
        client.connect(function (seesionId) {

            var message = {
                mId: mid
            };
            client.publish(config.jmsQueue.merchant_destination, JSON.stringify(message));
/*            client.disconnect(function () {
                console.log('jms ' + config.jmsQueue.merchant_destination + ' disconnect');
                if(cb){
                    cb();
                }
            })*/
        });
    },
    publicRecommendedDish : function (mid, did, cb) {
        var client = new Stomp(config.jmsServer.url, config.jmsServer.port, '', '');
        console.log('1111111111111')
        client.connect(function (seesionId) {

            var message = {
                mId: mid.toString(),
                dId: did.toString()
            };
            console.log('send!!!!!!!!!!!!')
            client.publish(config.jmsQueue.dish_destination, JSON.stringify(message));
            /*client.disconnect(function () {
                console.log('jms ' + config.jmsQueue.dish_destination + ' disconnect');
                if(cb){
                    cb();
                }
            })*/
        });
    },
    publishLowGrade : function (mid, cb) {
        var client = new Stomp(config.jmsServer.url, config.jmsServer.port, '', '');
        client.connect(function (seesionId) {

            var message = {
                mId: mid
            };
            client.publish(config.jmsQueue.lowGrade_destination, JSON.stringify(message));
/*            client.disconnect(function () {
                console.log('jms ' + config.jmsQueue.lowGrade_destination + ' disconnect');
                if(cb){
                    cb();
                }
            })*/
        })
    }
};

